package com.eeepay.eeepay_v2.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.text.format.DateFormat;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.util.MathUtils;
import com.eeepay.v2_library.adapter.ABBaseAdapter;
import com.eeepay.v2_library.adapter.ABViewHolder;

import java.util.Date;

import cn.eeepay.api.grpc.nano.WithdrawCashProto;

/**
 * 描述：账号记录的适配器
 * 作者：zhuangzeqin
 * 时间: 2017/5/3-11:52
 * 邮箱：zzq@eeepay.cn
 */
public class WithdrawalRecordAdapter extends ABBaseAdapter<WithdrawCashProto.AccountTranInfo> {

    public WithdrawalRecordAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_tx_record;
    }

    @Override
    public void convert(ABViewHolder holder, WithdrawCashProto.AccountTranInfo model) {
        if (model==null) return;
        String balance = String.format(mContext.getString(R.string.str_balance)+"%s",model.avaliBalance);
        holder.setText(R.id.tv_account_balance,balance);//账号余额
        String date = DateFormat.format("yyyy-MM-dd",new Date(model.recordDate)).toString();
        String time = DateFormat.format("HH:mm:ss",new Date(model.recordTime)).toString();
        holder.setText(R.id.tv_tx_time,date + " " + time);//时间

        String recordAmountStr = model.recordAmount;
        String transtype="";//<!-- 类型 credit: 入账; debit: 提现; freeze: 冻结; unfreeze: 解冻-->
        if (TextUtils.equals(model.transType,"credit")){
            transtype = "入账";
        } else if (TextUtils.equals(model.transType,"debit")){
            //交易金额为正则是 入账, 交易金额为负 则是冲正
            float recordAmount = Float.parseFloat(recordAmountStr);
            if(recordAmount < 0){
                transtype = "冲正";
                recordAmountStr = MathUtils.twoNumber(Math.abs(recordAmount));
            }else {
                transtype = "提现";
            }
        }
        else if (TextUtils.equals(model.transType,"freeze"))
            transtype = "冻结";
        else if (TextUtils.equals(model.transType,"unfreeze"))
            transtype = "解冻";
        holder.setText(R.id.tv_transaction_type,transtype);
        holder.setText(R.id.tv_transaction_amount, recordAmountStr);//交易金额(元)
    }
}
